package com.work.utils;

import java.sql.SQLException;

/**
 * @program: transfer
 * @description：事务管理器类，负责手动事务的开启、提交、回滚
 * @author: luffy
 * @create: 2020-07-01 10:22
 */
public class TransactionManager {
    private TransactionManager() {

    }

    private static TransactionManager transactionManager = new TransactionManager();

    public static TransactionManager getTransactionManager() {
        return transactionManager;
    }
    /**
     * 开启事务控制
     */
    public void beginTransaction() throws SQLException {
        ConnectionUtils.getInstance().getConnection().setAutoCommit(false);

    }

    /**
     * 提交事务
     */
    public void commit() throws SQLException {
        ConnectionUtils.getInstance().getConnection().commit();
    }

    /**
     * 回滚事务
     */
    public void rollback() throws SQLException {
        ConnectionUtils.getInstance().getConnection().rollback();

    }
}
